<template>
    <div>
        <Header :left="true" leftText="返回" title="调机审核" />

        <!-- 滑动区域，适应手机分辨率 -->
        <div class="textScroll">
            <!-- 文字信息 -->
            <van-row style="margin-top: 10px">
                <van-col>
                    <van-image width="40" height="30" style="margin-left: -10px" src="assets/block.png" />
                </van-col>
                <van-col class="message" style="margin-top: 5px">调机单据信息</van-col>
            </van-row>

            <div class="divMessage">
                <Field v-model="form.Id" :readonly="true" size="small" class="Field" center colon label="调机单ID" />
                <Field v-model="form.ProductionDate" rows="1" autosize style="font-weight: bold; color: #a9a9a9"
                    :readonly="true" label="生产日期" type="textarea" />
                <Field v-model="form.POrderID" :readonly="true" size="small" class="Field" center colon label="生产订单" />
                <Field v-model="form.MaterialID" :readonly="true" size="small" class="Field" center colon label="物料编号" />
                <Field v-model="form.MaterialName" :readonly="true" size="small" class="Field" center colon label="物料名称" />
                <Field :readonly="true" size="small" class="Field" center colon label="生产时间">
                    <template #input>
                        <span>从 {{ form.ProDatetimeFrom }} 至 {{ form.ProDatetimeTo }}</span>
                    </template>
                </Field>
                <Field v-model="form.QProblemID" :readonly="true" type="textarea" rows="2" class="Field2" label="异常原因">
                </Field>
                <Field v-model="form.ManageReasonID" :readonly="true" type="textarea" rows="2" class="Field2"
                    label="      ">
                </Field>
                <Field v-model="form.FunctionProblemID" :readonly="true" type="textarea" rows="2" class="Field2"
                    label="      ">
                </Field>
                <Field v-model="form.NoticeMemo" :readonly="true" size="small" class="Field" center colon label="通知单描述" />
                <Field v-model="form.ProductionBatch" :readonly="true" size="small" class="Field" center colon
                    label="生产批次" />
                <Field :readonly="true" size="small" class="Field" center colon label="班次">
                    <template #input>
                        {{ showShiftIDName(form.PShiftID) }}
                    </template>
                </Field>
                <Field v-model="form.MachineID" :readonly="true" size="small" class="Field" center colon label="设备代码" />
                <Field v-model="form.SampleAmount" :readonly="true" size="small" class="Field" center colon label="抽样数量" />
                <Field v-model="form.AbnormalAmount" :readonly="true" size="small" class="Field" center colon
                    label="异常数量" />
                <Field v-model="result" :readonly="true" size="small" class="Field" center colon label="质量要求" />
                <Field v-model="form.Reasons" :readonly="true" size="small" class="Field" center colon label="需注明的缺陷描述" />
                <!-- <Field v-model="form.AbnormalDescription" :readonly="true" size="small" class="Field" center colon label="缺陷描述" /> -->
                <Field v-model="form.Creator" :readonly="true" size="small" class="Field" center colon label="调机申请QC" />
                <Field v-model="form.CreateDatetime" :readonly="true" size="small" class="Field" center colon
                    label="创建时间" />
                <Field v-model="showAppearanceCheckRecord" :readonly="true" size="small" class="Field" center colon
                    label="外观检验记录" />
            </div>

            <van-row gutter="20">
                <van-col span="12">
                    <div style="margin: 16px">
                        <van-button color="#008792" round block type="info" @click="getRecord(form.AppearanceCheckRecord1)"
                            style="">查看外观检验不合格记录</van-button>
                    </div>
                </van-col>
                <van-col span="12">
                    <div style="margin: 16px">
                        <van-button color="#33a3dc" round block type="info" @click="checkSYS">查看实验室检验不合格项</van-button>
                    </div>
                </van-col>
            </van-row>

            <van-row gutter="20">
                <van-col span="12">
                    <div style="margin: 16px">
                        <van-button color="#1AB394" round block type="info" @click="openQA">打开质量辅助决策界面</van-button>
                    </div>
                </van-col>
                <van-col span="12">
                    <div style="margin: 16px">
                        <van-button color="#005831" round block type="info" @click="CheckTM">查看实验室复测记录</van-button>
                    </div>
                </van-col>
            </van-row>
            <!-- 品管领班审核 -->
            <div>
                <van-row style="margin-top: 10px">
                    <van-col>
                        <van-image width="40" height="30" style="margin-left: -10px" src="assets/block.png" />
                    </van-col>
                    <van-col class="message" style="margin-top: 5px">品管领班审核</van-col>
                </van-row>

                <Field name="是否同意" class="formstyle" label="是否同意" required>
                    <template #input>
                        <van-radio-group v-model="QCLeaderAgreeValue" direction="horizontal" @change="changeAgreeValue(1)"
                            :disabled="status > 1">
                            <van-radio name="1">同意</van-radio>
                            <van-radio name="0">不同意</van-radio>
                        </van-radio-group>
                    </template>
                </Field>

                <Field class="formstyle" v-model="form.QCLeaderMemo" required name="处置建议" label="处置建议"
                    placeholder="输入品管领班处置建议" :readonly="status > 1" rows="2" autosize type="textarea" maxlength="100"
                    show-word-limit />
                <van-field v-if="showEmployee && status == 1" required readonly class="formstyle" name="picker"
                    :value="EmployeeName1" label="生产现场主管审核" placeholder="点击选择生产现场主管" @click="showPickerEmployee = true" />
                <van-field v-if="status > 1" required readonly class="formstyle" name="picker" v-model="EmployeeName1"
                    label="品管领班" placeholder="品管领班" />
                <van-popup v-model="showPickerEmployee" position="bottom">
                    <van-picker show-toolbar :columns="columnsEmployeeND" @confirm="onConfirmEmployee"
                        @cancel="showPickerEmployee = false">
                        <template #option="option">
                            <div style="display: flex; flex-direction: column; align-items: center;">
                                <div>{{ option.EmployeeName }}</div>
                            </div>
                        </template>
                        <template #title>
                            <van-field v-model="searchKey1" placeholder="请输入搜索内容" clearable />
                        </template>
                    </van-picker>
                </van-popup>
                <van-field required readonly class="formstyle" label="审核时间" :value="nowDate" v-if="status == 1" />
                <van-field required readonly class="formstyle" label="审核时间" :value="date1" v-if="status != 1" />
            </div>
            <!-- 生产现场主管审核 -->
            <div>
                <van-row style="margin-top: 10px">
                    <van-col>
                        <van-image width="40" height="30" style="margin-left: -10px" src="assets/block.png" />
                    </van-col>
                    <van-col class="message" style="margin-top: 5px">生产现场主管审核</van-col>
                </van-row>

                <Field name="是否同意" class="formstyle" label="是否同意" required>
                    <template #input>
                        <van-radio-group v-model="TeamLeaderAgreeValue" direction="horizontal" @change="changeAgreeValue(2)"
                            :disabled="status > 2">
                            <van-radio name="1">同意</van-radio>
                            <van-radio name="0">不同意</van-radio>
                        </van-radio-group>
                    </template>
                </Field>
                <Field class="formstyle" v-model="form.TeamLeaderMemo" required name="处置建议" label="处置建议"
                    :readonly="status > 2" placeholder="生产现场主管输入处置意见" rows="2" autosize type="textarea" maxlength="100"
                    show-word-limit />
                <van-field v-if="showEmployee && status == 2" required readonly class="formstyle" name="picker"
                    :value="EmployeeName2" label="生产部门负责人审核" placeholder="点击选择生产部门负责人" @click="showPickerEmployee = true" />
                <van-field v-if="status > 2" required readonly class="formstyle" name="picker" v-model="EmployeeName2"
                    label="生产现场主管" placeholder="生产现场主管" />
                <van-popup v-model="showPickerEmployee" position="bottom">
                    <van-picker show-toolbar :columns="columnsEmployeeND" @confirm="onConfirmEmployee"
                        @cancel="showPickerEmployee = false">
                        <template #option="option">
                            <div style="display: flex; flex-direction: column; align-items: center;">
                                <div>{{ option.EmployeeName }}</div>
                            </div>
                        </template>
                        <template #title>
                            <van-field v-model="searchKey1" placeholder="请输入搜索内容" clearable />
                        </template>
                    </van-picker>
                </van-popup>
                <van-field required readonly class="formstyle" label="审核时间" :value="nowDate" v-if="status == 2" />
                <van-field required readonly class="formstyle" label="审核时间" :value="date2" v-if="status != 2" />
            </div>
            <!-- 生产部门负责人审核 -->
            <div>
                <van-row style="margin-top: 10px">
                    <van-col>
                        <van-image width="40" height="30" style="margin-left: -10px" src="assets/block.png" />
                    </van-col>
                    <van-col class="message" style="margin-top: 5px">生产部门负责人审核</van-col>
                </van-row>

                <Field name="是否同意" class="formstyle" label="是否同意" required>
                    <template #input>
                        <van-radio-group v-model="PrdManagerAgreeValue" direction="horizontal" @change="changeAgreeValue(3)"
                            :disabled="status > 3">
                            <van-radio name="1">同意</van-radio>
                            <van-radio name="0">不同意</van-radio>
                        </van-radio-group>
                    </template>
                </Field>
                <Field class="formstyle" v-model="form.PrdMangerMemo" required name="处置建议" label="处置建议"
                    :readonly="status > 3" placeholder="输入生产部门负责人处置建议" rows="2" autosize type="textarea" maxlength="100"
                    show-word-limit />
                <van-field v-if="showEmployee && status == 3" required readonly class="formstyle" name="picker"
                    :value="EmployeeName3" label="质量负责人审核" placeholder="点击选择质量负责人" @click="showPickerEmployee = true" />
                <van-field v-if="status > 3" required readonly class="formstyle" name="picker" v-model="EmployeeName3"
                    label="生产部门负责人" placeholder="生产部门负责人" />
                <van-popup v-model="showPickerEmployee" position="bottom">
                    <van-picker show-toolbar :columns="columnsEmployeeND" @confirm="onConfirmEmployee"
                        @cancel="showPickerEmployee = false">
                        <template #option="option">
                            <div style="display: flex; flex-direction: column; align-items: center;">
                                <div>{{ option.EmployeeName }}</div>
                            </div>
                        </template>
                        <template #title>
                            <van-field v-model="searchKey1" placeholder="请输入搜索内容" clearable />
                        </template>
                    </van-picker>
                </van-popup>
                <van-field required readonly class="formstyle" label="审核时间" :value="nowDate" v-if="status == 3" />
                <van-field required readonly class="formstyle" label="审核时间" :value="date3" v-if="status != 3" />
            </div>
            <!-- 质量负责人审核 -->
            <div>
                <van-row style="margin-top: 10px">
                    <van-col>
                        <van-image width="40" height="30" style="margin-left: -10px" src="assets/block.png" />
                    </van-col>
                    <van-col class="message" style="margin-top: 5px">质量负责人审核</van-col>
                </van-row>

                <Field name="是否同意" class="formstyle" label="是否同意" required>
                    <template #input>
                        <van-radio-group v-model="QCManagerAgreeValue" direction="horizontal" @change="changeAgreeValue(4)"
                            :disabled="status > 4">
                            <van-radio name="1">同意</van-radio>
                            <van-radio name="0">不同意</van-radio>
                        </van-radio-group>
                    </template>
                </Field>
                <Field class="formstyle" v-model="form.QCMangerMemo" required name="处置建议" label="处置建议"
                    placeholder="输入质量负责人处置建议" rows="2" autosize type="textarea" maxlength="100" show-word-limit
                    :readonly="status > 4" />
                <van-field v-if="showEmployee && status == 4" required readonly class="formstyle" name="picker"
                    :value="EmployeeName4" label="利润点负责人审核" placeholder="点击选择利润点负责人" @click="showPickerEmployee = true" />
                <van-field v-if="status > 4" required readonly class="formstyle" name="picker" v-model="EmployeeName4"
                    label="质量负责人" placeholder="质量负责人" />
                <van-popup v-model="showPickerEmployee" position="bottom">
                    <van-picker show-toolbar :columns="columnsEmployeeND" @confirm="onConfirmEmployee"
                        @cancel="showPickerEmployee = false">
                        <template #option="option">
                            <div style="display: flex; flex-direction: column; align-items: center;">
                                <div>{{ option.EmployeeName }}</div>
                            </div>
                        </template>
                        <template #title>
                            <van-field v-model="searchKey1" placeholder="请输入搜索内容" clearable />
                        </template>
                    </van-picker>
                </van-popup>
                <van-field required readonly class="formstyle" label="审核时间" :value="nowDate" v-if="status == 4" />
                <van-field required readonly class="formstyle" label="审核时间" :value="date4" v-if="status != 4" />
            </div>
            <!-- 利润点负责人审核 -->
            <div>
                <van-row style="margin-top: 10px">
                    <van-col>
                        <van-image width="40" height="30" style="margin-left: -10px" src="assets/block.png" />
                    </van-col>
                    <van-col class="message" style="margin-top: 5px">利润点负责人审核</van-col>
                </van-row>

                <Field name="是否同意" class="formstyle" label="是否同意" required>
                    <template #input>
                        <van-radio-group v-model="FactoryManagerAgreeValue" direction="horizontal"
                            @change="changeAgreeValue(5)">
                            <van-radio name="1">同意</van-radio>
                            <van-radio name="0">不同意</van-radio>
                        </van-radio-group>
                    </template>
                </Field>
                <Field class="formstyle" v-model="form.FactoryMangerMemo" required name="处置建议" label="处置建议"
                    placeholder="输入利润点负责人处置建议" rows="2" autosize type="textarea" maxlength="100" show-word-limit />
                <van-field required readonly class="formstyle" label="审核时间" :value="nowDate" />
            </div>
        </div>

        <!-- 故障类型弹窗 -->
        <van-popup v-model="faultShowPicker" round position="bottom">
            <van-picker showPicker="false" title="故障类型选择" value-key="text" show-toolbar @confirm="faultOnConfirm"
                :columns="faultTypes" @cancel="faultShowPicker = false" default-index="0" />
        </van-popup>

        <!-- 暂停原因 -->
        <van-popup v-model="resonShow" round position="bottom">
            <van-picker showPicker="false" title="暂停原因选择" value-key="text" show-toolbar @confirm="resonConfirm"
                :columns="stopReson" @cancel="resonShow = false" default-index="0" />
        </van-popup>
    </div>
</template>
<script>
import {
    Icon,
    NoticeBar,
    Button,
    Row,
    Tag,
    Checkbox,
    Pagination,
    popup,
    Loading,
    Popup,
    Panel,
    ImagePreview,
    Toast,
    tab,
    tabs,
    Divider,
    Image as VanImage,
    Field,
    CellGroup,
    Cell,
    Picker,
    Uploader,
    Dialog,
    Col,
    RadioGroup,
    Radio,
} from "vant";
import { _httpClient as _httpClientApi } from "@/libs/api";
import { _httpClient } from "@/libs/apisie";
import { storage } from "@/libs/utils";
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(tab);
Vue.use(tabs);
Vue.use(Button);
Vue.use(Col);
Vue.use(Row);
Vue.use(Icon);
Vue.use(VanImage);
Vue.use(Divider);
Vue.use(Checkbox);
Vue.use(Pagination);
Vue.use(Panel);
Vue.use(Dialog);
Vue.use(Picker);
Vue.use(popup);
Vue.use(Uploader);
Vue.use(Loading);
Vue.use(Field);
Vue.use(RadioGroup);
Vue.use(Radio);
import Header from "@/components/header.vue";
import apicloud from "@/libs/apicloud";
export default {
    name: "QCCommissioningAcceptanceItem",
    components: {
        Button,
        NoticeBar,
        Header,
        ImagePreview,
        Icon,
        Row,
        tab,
        popup,
        Popup,
        tabs,
        Tag,
        VanImage,
        Toast,
        Divider,
        Field,
        CellGroup,
        Cell,
        Uploader,
        Picker,
        Dialog,
        Col,
        RadioGroup,
        Radio,
    },

    data() {
        return {
            btnLoading: false,
            winName: "", //窗口名
            user: [], //当前登录用户
            //多媒体文件
            photoList: [
                //图片
            ],
            pictureNum: 0, //照片数量
            playing: "播放中...", //语音播放中字幕
            audioLoad: false, // 语音播放中
            audioStop: true, // 语音暂停
            photoShow: false, //照片显示控制
            vedioShow: false, //视频显示控制
            audioShow: false, //语音显示控制
            vedioList: [], //视频
            audioPath: "", //语音
            searchKey1: "",
            resonShow: false, //暂停原因录入弹窗是否显示
            btnStartShow: false, //开始调机按钮权限
            btnAssignShow: true, //任务转派按钮权限
            btnStopShow: true, //调机暂停按钮权限
            btnEndShow: true, //调机结束按钮权限
            stopResonValue: "", //调机暂停原因
            showAppearanceCheckRecord: "",
            equipRepairVo: {
                id: null,
                eqKey: null,
                equipName: "",
                equipCode: "",
                remark: null,
                picList: [],
                videoList: [],
                audioList: [],
                resTime: null,
                requestUser: "",
                repairReson: "",
            },
            faultShowPicker: false, //故障原因下拉框
            screenWidth: 0,
            checked: true,
            active: 2,
            helpUser: [], //协助人
            helpUserStr: "", //协助人拼接字符串
            helpUserNameStr: "", //协助人拼接字符串
            helpUserContent: "", //协助人拼接字段
            faultType: "", //故障类型
            sparePart: [], //备件记录
            sparePartContent: "", //备件拼接字段
            fileUrl: "",
            form: [],
            faultTypes: [],
            stopReson: [],
            uploadSuccess: false,
            columnsDealType: [],
            columnsEmployee: [],
            columnsQProblem: [],
            columnsEmployeeND: [],
            columnsshift: [],
            showPickerEmployee: false,
            showPickerQProblem: false,
            item: {},
            valuepDealTypeName: "",
            EmployeeName1: "",
            EmployeeName2: "",
            EmployeeName3: "",
            EmployeeName4: "",
            date1: "",
            date2: "",
            date3: "",
            date4: "",
            columnsEmployees: [],
            time: "",
            FactoryID: "",
            valuepShiftName: "",
            CheckTypeName: "",
            QProblemName: "",
            valueteamid: "",
            nowDate: "",
            EmployeeID: "",
            result: [],
            //领班
            QCLeaderAgreeValue: "",
            //带版主管
            TeamLeaderAgreeValue: "",
            //质量负责人
            QCManagerAgreeValue: "",
            //生产部门负责人
            PrdManagerAgreeValue: "",
            //利润点负责人
            FactoryManagerAgreeValue: "",
            //当前状态
            status: "",
            //是否显示人员
            showEmployee: false,
            PositionID: ""
        };
    },
    created: function () {
        let oldHight = api.winWidth;
        this.screenWidth = oldHight;
        this.user = JSON.parse(storage.get("user"));
        this.user.userId = this.user.userName;
        // this.equipRepairVo.resTime = this.getNowTime()
        //页面赋值
        //this.form = api.pageParam.item;
        // alert(api.pageParam.item);
        this.initForm(api.pageParam.item);
        // // alert(JSON.stringify(this.form));
        this.nowDate = this.getNowTime();
        this.initList();
        this.getUsername(this.form.Creator)

        this.getQualityProblems();
        this.getshift();
        this.getAppearanceCheckRoward()

    },
    watch: {  //实时监听搜索输入内容
        'searchKey': {
            handler(newVal) {
                let key = String(newVal);
                //alert(key);
                key = key.replace(/\s*/g, "");
                const reg = new RegExp(key, "ig");
                /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
                this.searchColumns = this.columnspline.filter(item => item.plineName.match(reg) != null);
                //alert(this.searchColumns);
            },
            deep: true,
            immediate: true,
        },

        'searchKey1': {
            handler(newVal) {
                let key = String(newVal);
                //alert(key);
                key = key.replace(/\s*/g, "");
                const reg = new RegExp(key, "ig");
                /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
                this.columnsEmployeeND = this.columnsEmployee.filter(item => item.EmployeeName.match(reg) != null);
                //alert(this.searchColumns);
            },
            deep: true,
            immediate: true,
        },

        'searchKey2': {
            handler(newVal) {
                let key = String(newVal);
                //alert(key);
                key = key.replace(/\s*/g, "");
                const reg = new RegExp(key, "ig");
                /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
                this.statColumn2 = this.statColumn.filter(item => item.POrderIDAndMaterialName.match(reg) != null);
                //alert(this.searchColumns);
            },
            deep: true,
            immediate: true,
        },
    },
    methods: {
        async initForm(val) {
            let _this = this;
            try {
                let res4 = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/QualityAbnormalNotice/GetEntity?id=" + val)

                if (res4.Data.length > 0) {
                    _this.form = res4.Data[0]
                }
            } catch (e) {
                alert(JSOn.stringify(e))
            }
        },
        async getUsername(id) {

            try {

                let res4 = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + id)

                if (res4.Data.length > 0) {

                    this.form.Creator = res4.Data[0].EmployeeName
                    return
                }
            } catch (e) {
                alert(JSOn.stringify(e))
            }
            this.form.Creator = id
        },

        getNowTime() {
            let dateTime;
            let yy = new Date().getFullYear();
            let mm = new Date().getMonth() + 1;
            let dd = new Date().getDate();
            let hh = new Date().getHours();
            let mf =
                new Date().getMinutes() < 10
                    ? "0" + new Date().getMinutes()
                    : new Date().getMinutes();
            let ss =
                new Date().getSeconds() < 10
                    ? "0" + new Date().getSeconds()
                    : new Date().getSeconds();
            dateTime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
            return dateTime;
        },
        async initList() {
            // this.getEmployeeID3()
            if (this.form.Require1) {
                this.result.push("及时调机整改");
            }
            if (this.form.Require2) {
                this.result.push("停机调整");
            }
            if (this.form.Require3) {
                this.result.push("产品要求返工，发出返工通知单");
            }
            if (this.form.Require4) {
                this.result.push("在线自检挑出");
            }



            //判断审批流程状态
            if (!this.form.QCLeaderChecked) {
                //品管领班未审核
                this.status = 1;
            } else if (this.form.QCLeaderChecked && this.form.QCLeaderAgree && !this.form.TeamLeaderChecked) {//品管领班审核且同意,主管未审核
                //生产现场主管审核
                this.status = 2;
            } else if (this.form.TeamLeaderChecked && !this.form.TeamLeaderAgree && !this.form.PrdManagerChecked) {//生产现场主管已审核且不同意，生产部门负责人未审批

                //生产审核
                this.status = 3;
            } else if (this.form.PrdManagerChecked && !this.form.PrdManagerAgree && !this.form.QCManagerChecked) {//生产部门负责人审核且不同意 质量未审核

                //质量审核
                this.status = 4;
            } else if (this.form.QCManagerChecked && this.form.QCManagerAgree && !this.form.FactoryManagerChecked) {//质量负责人审核且同意 利润点未审批
                //利润点负责人审批
                this.status = 5;
                //alert("111")
            }

            // //领班
            // QCLeaderAgreeValue: "",
            // //带版主管
            // TeamLeaderAgreeValue: "",
            // //质量负责人
            // QCManagerAgreeValue: "",
            // //生产部门负责人
            // PrdManagerAgreeValue: "",
            // //利润点负责人
            // FactoryManagerAgreeValue: "",
            try {

                if (this.form.QCLeaderUserID != "") {
                    let res4 = await _httpClient.get(
                        _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + this.form.QCLeaderUserID)
                    this.QCLeaderAgreeValue = this.form.QCLeaderAgree ? "1" : "0"
                    this.date1 = this.form.QCLeaderCheckDatetime

                    if (res4.Data.length > 0) {
                        this.EmployeeName1 = res4.Data[0].EmployeeName
                    }

                }

                if (this.form.TeamLeaderUserID != "") {

                    let res4 = await _httpClient.get(
                        _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + this.form.TeamLeaderUserID)
                    this.TeamLeaderAgreeValue = this.form.TeamLeaderAgree ? "1" : "0"
                    this.date2 = this.form.TeamLeaderCheckDatetime
                    if (res4.Data.length > 0) {
                        this.EmployeeName2 = res4.Data[0].EmployeeName
                    }
                }


                if (this.form.PrdMangerUserID != "") {
                    let res4 = await _httpClient.get(
                        _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + this.form.PrdMangerUserID)
                    this.PrdManagerAgreeValue = this.form.PrdManagerAgree ? "1" : "0"
                    this.date3 = this.form.PrdManagerCheckDatetime
                    if (res4.Data.length > 0) {
                        this.EmployeeName3 = res4.Data[0].EmployeeName
                    }
                }

                if (this.form.QCMangerUserID != "") {

                    let res4 = await _httpClient.get(
                        _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + this.form.QCMangerUserID)
                    this.QCManagerAgreeValue = this.form.QCManagerAgree ? "1" : "0"
                    this.date4 = this.form.QCManagerCheckDatetime
                    if (res4.Data.length > 0) {
                        this.EmployeeName4 = res4.Data[0].EmployeeName
                    }
                }

                // alert(JSON.stringify(this.form))
            } catch (e) {
                Toast(JSON.stringify(e))
            }
            // alert(JSON.stringify(this.form))

        },
        openQA() {
            let _this = this
            // alert(_this.form.POrderID)
            api.openWin({
                name: 'qAssistance',
                url: './qAssistance-qualityAssistance.html',
                pageParam: {
                    POrderID: _this.form.POrderID,
                    PlineID: _this.form.MachineID
                }
            });


        },

        getRecord(id) {
            if (id = "" || id == 0 || id == null) {
                alert("没有外观检验不合格记录");
                return;
            }


            api.openWin({
                name: 'qCcheckReview',
                url: './quality-qCcheckReview.html',
                pageParam: {
                    id: id
                }
            });

        },
        async CheckTM() {
            // let id = this.form.LaboratoryCheckRecord1


            // if (id == "" || id == null || id == undefined) {
            //     Toast.clear()
            //     Toast.fail("当前没有维护实验室复测记录，无法获取实验室复测记录！")
            //     return
            // }

            // api.openWin({
            //     name: 'viewlaboratorytest1',
            //     url: './equipmentsj-viewlaboratorytest1.html',
            //     pageParam: {
            //         id: this.form.LaboratoryCheckRecord1
            //     }
            // });

            let id = this.form.LaboratoryCheckRecord1
            let CheckItem = this.form.CheckItem;
            let CheckBatch = this.form.CheckBatch;
            if (CheckBatch == "全项检验") {
                CheckBatch = "问题产品复核检验-全项"
            }
            else {
                CheckBatch = "问题产品复核检验-过程"
            }

            if (id == "" || id == null || id == undefined) {
                Toast.clear()
                Toast.fail("当前没有维护实验室复测记录，无法获取复测记录！")
                return
            }

            api.openWin({
                name: 'viewlaboratorytest1',
                url: './equipmentsj-viewlaboratorytest1.html',
                pageParam: {
                    id: this.form.LaboratoryCheckRecord1,
                    CheckBatch: CheckBatch,
                    CheckItem: this.form.CheckItem
                }
            });
        },
        async checkSYS() {
            // let id = this.form.LaboratoryCheckRecord1


            // if (id == "" || id == null || id == undefined) {
            //     Toast.clear()
            //     Toast.fail("当前没有维护实验室检验记录，无法获取不合格记录！")
            //     return
            // }

            // api.openWin({
            //     name: 'viewlaboratorytest',
            //     url: './equipmentsj-viewlaboratorytest.html',
            //     pageParam: {
            //         id: this.form.LaboratoryCheckRecord1
            //     }
            // });

            let id = this.form.LaboratoryCheckRecord1;
            let CheckBatch = this.form.CheckBatch;
            let CheckItem = this.form.CheckItem;

            if (id == "" || id == null || id == undefined) {
                Toast.clear()
                Toast.fail("当前没有维护实验室检验记录，无法获取不合格记录！")
                return
            }

            api.openWin({
                name: 'viewlaboratorytest',
                url: './equipmentsj-viewlaboratorytest.html',
                pageParam: {
                    id: this.form.LaboratoryCheckRecord1,
                    CheckBatch: this.form.CheckBatch,
                    CheckItem: this.form.CheckItem
                }
            });

        },
        async getAppearanceCheckRoward() {
            try {
                let res = await _httpClient.get(
                    _httpClient.getApiPrefix() +
                    "/QualityAppearanceCheck/GetEntityName?FieldValue=" + this.form.AppearanceCheckRecord1);
                if (res.HttpCode === "200") {
                    this.showAppearanceCheckRecord = res.Data
                } else {
                    this.showAppearanceCheckRecord = this.form.AppearanceCheckRecord1
                }

            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },
        //提交审批
        submitCheck() {
            var body = {};
            body.Id = this.form.Id;
            //判断状态
            if (this.status == 1) {
                //质量制程主管
                body.QCLeaderAgree = this.form.QCLeaderAgree;
                body.QCLeaderMemo = this.form.QCLeaderMemo;
                body.QCLeaderUserID = this.user.userId;
                body.QCLeaderCheckDatetime = this.nowDate;
                body.QCLeaderChecked = true;
                //需要调机 选择生产现场主管
                if (this.form.QCLeaderAgree) {
                    body.TeamLeaderUserID = this.EmployeeID
                    this.sendmessage(1, false, false);
                } else {
                    //不需要调机 直接结束     
                    //传入终审人
                    body.FixedMan = this.user.userId;
                    //最终审时间
                    body.FixedDatetime = this.nowDate;
                    //终审是否需要调机
                    body.FixedAgree = false;

                    this.sendmessage(1, true, false);
                }
            } else if (this.status == 2) {
                //生产现场主管审核
                body.TeamLeaderAgree = this.form.TeamLeaderAgree;
                body.TeamLeaderMemo = this.form.TeamLeaderMemo;
                body.TeamLeaderCheckDatetime = this.nowDate;
                body.TeamLeaderChecked = true;
                //需要调机 直接结束
                if (this.form.TeamLeaderAgree) {
                    //传入终审人
                    body.FixedMan = this.user.userId;
                    //最终审时间
                    body.FixedDatetime = this.nowDate;
                    //终审是否需要调机
                    body.FixedAgree = true;

                    this.sendmessage(2, true, true);
                } else {
                    //不需要调机 询问生产部门负责人     
                    body.PrdMangerUserID = this.EmployeeID;

                    this.sendmessage(2, false, false);
                }
            } else if (this.status == 3) {
                //生产部门负责人审核
                body.PrdManagerAgree = this.form.PrdManagerAgree;
                body.PrdMangerMemo = this.form.PrdMangerMemo;
                body.PrdManagerCheckDatetime = this.nowDate;
                body.PrdManagerChecked = true
                //需要调机 直接结束
                if (this.form.PrdManagerAgree) {
                    //传入终审人
                    body.FixedMan = this.user.userId;
                    //最终审时间
                    body.FixedDatetime = this.nowDate;
                    //终审是否需要调机
                    body.FixedAgree = true;

                    this.sendmessage(3, true, true);
                } else {
                    //不需要调机 选择质量负责人   
                    body.QCMangerUserID = this.EmployeeID;

                    this.sendmessage(3, false, false);
                }
            } else if (this.status == 4) {//质量负责人审核
                body.QCManagerAgree = this.form.QCManagerAgree;
                body.QCMangerMemo = this.form.QCMangerMemo;
                body.QCManagerCheckDatetime = this.nowDate;
                body.QCManagerChecked = true;
                //需要调机 选择利润点负责人
                if (this.form.QCManagerAgree) {
                    body.FactoryMangerUserID = this.EmployeeID;
                    this.sendmessage(4, false, false);
                } else {
                    //不需要调机 直接结束              
                    //传入终审人
                    body.FixedMan = this.user.userId;
                    //最终审时间
                    body.FixedDatetime = this.nowDate;
                    //终审是否需要调机
                    body.FixedAgree = false;
                    this.sendmessage(4, true, false);
                }
            } else if (this.status == 5) {
                //利润点负责人审核
                body.FactoryManagerAgree = this.form.FactoryManagerAgree;
                body.FactoryMangerMemo = this.form.FactoryMangerMemo;
                body.FactoryManagerCheckDatetime = this.nowDate;
                body.FactoryManagerChecked = true;
                //传入终审人
                body.FixedMan = this.user.userId;
                //最终审时间
                body.FixedDatetime = this.nowDate;
                //需要调机 直接结束 
                if (this.form.FactoryManagerAgree) {
                    //终审是否需要调机
                    body.FixedAgree = true;
                    this.sendmessage(5, true, true);
                } else {
                    //不需要调机 直接结束    
                    //终审是否需要调机
                    body.FixedAgree = false;
                    this.sendmessage(5, true, false);
                }
            }
            //alert(JSON.stringify(body))
            this.SaveCheckEntity(body)
            //发送调机终审消息
            // if (body.FixedMan == this.user.userId) {

            // }
        },
        //审核节点，是否终审，是否同意
        async sendmessage(index, isfix, isend) {
            try {
                let _this = this;

                let eventDescription = "";
                let eventDatetime = _this.getNowTime();
                let eventTypeID = "N3";
                let eventID = "";
                let messageContent = "";
                let msgContentTypeID = "";
                let pLineID = _this.form.MachineID;
                let machineID = "";
                let pShiftID = "";
                let teamID = "";
                let pOrderID = "";
                let productionBarcode = "";
                let materialBarcode = "";
                let relatedEmployee = "";
                let messageStatus = "";
                let processBatchID = "";
                let beginDatetime = _this.getNowTime();
                let sendFinished = false;
                let closed = false;

                let msg1 = "同意调机，请调机人员按照要求进行调机！";
                let msg2 = "不同意调机，请相关岗位知悉！";

                //质量制程主管
                if (index == 1 && isfix == false) {
                    msgContentTypeID = "ABN02";
                    eventID = "ABN02";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被品管领班审核，请生产现场主管进行调机单后续审核！";
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被品管领班审核.请生产现场主管进行调机单后续审核！";
                }
                else if (index == 1 && isfix == true && isend == true) {
                    msgContentTypeID = "ABN06";
                    eventID = "ABN06";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被品管领班审核，" + msg1;
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被品管领班审核，" + msg1;
                }
                else if (index == 1 && isfix == true && isend == false) {
                    msgContentTypeID = "ABN06";
                    eventID = "ABN06";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被品管领班审核，" + msg2;
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被品管领班审核，" + msg2;
                }

                //生产现场主管
                if (index == 2 && isfix == false) {
                    msgContentTypeID = "ABN03";
                    eventID = "ABN03";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被生产现场主管审核，请生产负责人进行调机单后续审核！";
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被生产现场主管审核.请生产负责人进行调机单后续审核！";
                }
                else if (index == 2 && isfix == true && isend == true) {
                    msgContentTypeID = "ABN06";
                    eventID = "ABN06";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被生产现场主管审核，" + msg1;
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被生产现场主管审核." + msg1;
                }
                else if (index == 2 && isfix == true && isend == false) {
                    msgContentTypeID = "ABN06";
                    eventID = "ABN06";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被生产现场主管审核，" + msg2;
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被生产现场主管审核." + msg2;
                }


                //生产负责人
                if (index == 3 && isfix == false) {
                    msgContentTypeID = "ABN04";
                    eventID = "ABN04";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被生产负责人审核，请质量负责人进行调机单后续审核！";
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被生产负责人审核.请质量负责人进行调机单后续审核！";
                }
                else if (index == 3 && isfix == true && isend == true) {
                    msgContentTypeID = "ABN06";
                    eventID = "ABN06";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被生产负责人审核，" + msg1;
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被生产负责人审核." + msg1;
                }
                else if (index == 3 && isfix == true && isend == false) {
                    msgContentTypeID = "ABN06";
                    eventID = "ABN06";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被生产负责人审核，" + msg2;
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被生产负责人审核." + msg2;
                }

                //质量负责人
                if (index == 4 && isfix == false) {
                    msgContentTypeID = "ABN05";
                    eventID = "ABN05";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被质量负责人审核，请利润点负责人进行调机单后续审核！";
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被质量负责人审核,请利润点负责人进行调机单后续审核！";
                }
                else if (index == 4 && isfix == true && isend == true) {
                    msgContentTypeID = "ABN06";
                    eventID = "ABN06";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被质量负责人审核，" + msg1;
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被质量负责人审核." + msg1;
                }
                else if (index == 4 && isfix == true && isend == false) {
                    msgContentTypeID = "ABN06";
                    eventID = "ABN06";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被质量负责人审核，" + msg2;
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被质量负责人审核." + msg2;
                }

                //利润点负责人
                if (index == 5 && isfix == true && isend == true) {
                    msgContentTypeID = "ABN06";
                    eventID = "ABN06";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被利润点负责人审核，" + msg1;
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被利润点负责人审核." + msg1;
                }
                else if (index == 5 && isfix == true && isend == false) {
                    msgContentTypeID = "ABN06";
                    eventID = "ABN06";
                    eventDescription = "订单:" + _this.form.POrderID + "的调机单已被利润点负责人审核，" + msg2;
                    messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.result + "调机单已被利润点负责人审核." + msg2;
                }

                let bodysss = {
                    eventDescription: eventDescription,
                    eventDatetime: eventDatetime,
                    eventTypeID: eventTypeID,
                    eventID: eventID,
                    messageContent: messageContent,
                    msgContentTypeID: msgContentTypeID,
                    factoryID: "TC00",
                    pLineID: pLineID,
                    machineID: machineID,
                    pShiftID: pShiftID,
                    teamID: teamID,
                    pOrderID: pOrderID,
                    productionBarcode: productionBarcode,
                    materialBarcode: materialBarcode,
                    relatedEmployee: relatedEmployee,
                    messageStatus: messageStatus,
                    processBatchID: processBatchID,
                    beginDatetime: beginDatetime,
                    sendFinished: sendFinished,
                    closed: closed
                };
                try {
                    let res = await _httpClient.post(
                        _httpClient.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
                        {
                            body: bodysss,
                        }
                    );
                    //alert(JSON.stringify(res));
                    if (res.Message == null) {
                        Toast.clear();
                        Toast.success("发送成功");
                        // setTimeout(function () {
                        //   _this.$ac.closeWin();
                        // }, 2000);
                    } else {
                        Toast.clear();
                        Toast.fail("发送失败");
                    }
                } catch (e) {
                    Toast.fail(JSON.stringify(e));
                }
            } catch (error) {
                alert(error);
            }

        },
        async SaveCheckEntity(body) {
            let _this = this;
            Toast.loading({
                mask: true,
                forbidClick: true,
                duration: 0,
                message: "请稍等...",
            });
            try {
                let res = await _httpClient.post(
                    _httpClient.getApiPrefix() + "/QualityAbnormalNotice/SaveEntity",
                    {
                        body: body,
                    }
                );
                if (res.Message != null) {
                    //message不为空,有报错信息，打卡失败 暂时这样判断
                    Toast.clear();
                    Toast.fail("保存失败,请核对信息！");
                } else {
                    //打卡成功
                    Toast.clear();
                    Toast.success("保存成功！");
                    setTimeout(function () {
                        _this.$ac.closeWin();
                    }, 2000);
                }
            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },
        //获取员工列表
        async getEmployeeID() {
            this.columnsEmployee = []
            // alert(_httpClient.getApiPrefix() + "/Employee/GetList?PositionID=" + this.PositionID)
            let _this = this;
            try {
                let res = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=" + this.PositionID,
                );
                if (res.HttpCode === "200") {
                    let temp = res.Data.map(item => ({ EmployeeID: item.EmployeeID, EmployeeName: item.EmployeeName }))
                    temp.forEach(item => {
                        _this.columnsEmployee.push(item);
                        _this.columnsEmployeeND.push(item);
                    })
                }
            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },

        //获取员工列表
        async getEmployeeID1() {
            let _this = this;
            try {
                let res = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW35",
                );
                if (res.HttpCode === "200") {
                    let temp = res.Data.map(item => ({ EmployeeID: item.EmployeeID, EmployeeName: item.EmployeeName }))
                    temp.forEach(item => {
                        _this.columnsEmployee.push(item);
                        _this.columnsEmployeeND.push(item);
                    })
                }
            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },




        //获取GW20+GW36员工列表
        async getEmployeeIDOfGW20GW36() {
            this.columnsEmployee = []
            // alert(_httpClient.getApiPrefix() + "/Employee/GetList?PositionID=" + this.PositionID)
            let _this = this;
            try {
                let res = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW20",
                );
                let res1 = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW36",
                );
                if (res.HttpCode === "200"&&res1.HttpCode === "200") {
                    let temp = res.Data.map(item => ({ EmployeeID: item.EmployeeID, EmployeeName: item.EmployeeName }))
                    temp.forEach(item => {
                        _this.columnsEmployee.push(item);
                        _this.columnsEmployeeND.push(item);
                    })

                    let temp1 = res1.Data.map(item1 => ({ EmployeeID: item1.EmployeeID, EmployeeName: item1.EmployeeName }))
                    temp1.forEach(item1 => {
                        _this.columnsEmployee.push(item1);
                        _this.columnsEmployeeND.push(item1);
                    })
                }
            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },



        onConfirmEmployee(value, index) {
            if (this.status == 1) {
                this.EmployeeID = this.columnsEmployeeND[index].EmployeeID;
                this.EmployeeName1 = this.columnsEmployeeND[index].EmployeeName;
            }
            if (this.status == 2) {
                this.EmployeeID = this.columnsEmployeeND[index].EmployeeID;
                this.EmployeeName2 = this.columnsEmployeeND[index].EmployeeName;
            }
            if (this.status == 3) {
                this.EmployeeID = this.columnsEmployeeND[index].EmployeeID;
                this.EmployeeName3 = this.columnsEmployeeND[index].EmployeeName;
            }
            if (this.status == 4) {
                this.EmployeeID = this.columnsEmployeeND[index].EmployeeID;
                this.EmployeeName4 = this.columnsEmployeeND[index].EmployeeName;
            }

            this.showPickerEmployee = false;
        },
        //获取班次信息
        async getshift() {
            let _this = this;
            try {
                let res = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/ProductionShift/GetList?factoryID=" + _this.form.FactoryID,
                );
                if (res.HttpCode === "200") {
                    for (let index = 0; index < res.Data.length; index++) {
                        if (res.Data[index].Actived == false) {
                            delete res.Data[index];
                        }
                    }
                    let shiftMap = res.Data.map(item => ({ pShiftName: item.PShiftName, pShiftID: item.PShiftID }))
                    _this.columnsshift = shiftMap
                }
            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },
        showShiftIDName(pShiftID) {
            var pShiftName;
            this.columnsshift.forEach(item => {
                if (item.pShiftID === pShiftID) {
                    pShiftName = item.pShiftName;

                }
            })
            return pShiftName
        },
        showQProblemID(QProblemID) {
            var QProblemName;
            this.columnsQProblem.forEach(item => {
                if (item.QProblemID === QProblemID) {
                    QProblemName = item.QProblemName;
                }
            })
            return QProblemName;
        },
        showDealType(type) {
            var DealTypeName;
            this.columnsDealType.forEach(item => {
                if (item.DealTypeID === type) {
                    DealTypeName = item.DealTypeName;
                }
            })
            return DealTypeName;
        },
        changeAgreeValue(index) {

            if (this.status != index) {
                return
            }

            //如果合格 隐藏页面 直接提交
            if (index == 1) {
                this.EmployeeName1 = ""
                this.EmployeeID = ""
                if (this.QCLeaderAgreeValue == "1") {
                    this.columnsEmployeeND = [];
                    this.form.QCLeaderAgree = true;
                    this.form.QCLeaderMemo = this.getNowTime() + ":" + "品管领班:" + this.user.employeeName + "同意调机!"
                    this.showEmployee = true;
                    this.PositionID = "GW34";
                    this.getEmployeeID();
                    this.getEmployeeID1();
                } else if (this.QCLeaderAgreeValue == "0") {
                    //若不同意
                    this.form.QCLeaderAgree = false;
                    this.form.QCLeaderMemo = this.getNowTime() + ":" + "品管领班:" + this.user.employeeName + "不同意调机!"
                    this.showEmployee = false;
                }
            }
            if (index == 2) {
                this.EmployeeName2 = ""
                this.EmployeeID = ""
                if (this.TeamLeaderAgreeValue == "1") {
                    //若主管同意
                    this.form.TeamLeaderAgree = true;
                    this.form.TeamLeaderMemo = this.getNowTime() + ":" + "生产现场主管:" + this.user.employeeName + "同意调机!"
                    this.showEmployee = false;
                } else if (this.TeamLeaderAgreeValue == "0") {
                    this.columnsEmployeeND = [];
                    //若主管不同意
                    this.form.TeamLeaderAgree = false;
                    this.form.TeamLeaderMemo = this.getNowTime() + ":" + "生产现场主管:" + this.user.employeeName + "不同意调机!"
                    this.showEmployee = true;
                    //this.PositionID = "GW20";
                    //this.getEmployeeID();
                    this.getEmployeeIDOfGW20GW36();
                }
            }

            if (index == 4) {
                this.EmployeeName4 = ""
                this.EmployeeID = ""
                if (this.QCManagerAgreeValue == "1") {

                    this.columnsEmployeeND = [];
                    //若质量负责人同意
                    this.form.QCManagerAgree = true;
                    this.form.QCMangerMemo = this.getNowTime() + ":" + "质量负责人:" + this.user.employeeName + "同意调机!";
                    this.showEmployee = true;
                    this.PositionID = "GW01";
                    this.getEmployeeID();
                } else if (this.QCManagerAgreeValue == "0") {
                    //若质量负责人不同意
                    this.form.QCManagerAgree = false;
                    this.form.QCMangerMemo = this.getNowTime() + ":" + "质量负责人:" + this.user.employeeName + "不同意调机!";
                    this.showEmployee = false;
                }
            }

            if (index == 3) {
                this.EmployeeName3 = ""
                this.EmployeeID = ""
                if (this.PrdManagerAgreeValue == "1") {
                    //若生产部门负责人同意
                    this.form.PrdManagerAgree = true;
                    this.form.PrdMangerMemo = this.getNowTime() + ":" + "生产部门负责人:" + this.user.employeeName + "同意调机!"
                    this.showEmployee = false;
                } else if (this.PrdManagerAgreeValue == "0") {
                    this.columnsEmployeeND = [];
                    //若生产负责不人同意
                    this.form.PrdManagerAgree = false;
                    this.form.PrdMangerMemo = this.getNowTime() + ":" + "生产部门负责人:" + this.user.employeeName + "不同意调机!"
                    this.showEmployee = true;
                    this.PositionID = "GW07";
                    this.getEmployeeID();
                }
            }

            if (index == 5) {
                if (this.FactoryManagerAgreeValue == "1") {
                    //若利润点负责人同意
                    this.form.FactoryManagerAgree = true;
                    this.form.FactoryMangerMemo = this.getNowTime() + ":" + "利润点负责人:" + this.user.employeeName + "同意调机!"
                } else if (this.FactoryManagerAgreeValue == "0") {
                    //若利润点负责不人同意
                    this.form.FactoryManagerAgree = false;
                    this.form.FactoryMangerMemo = this.getNowTime() + ":" + "利润点负责人:" + this.user.employeeName + "不同意调机!"
                }
            }

        },
        //获取缺陷原因
        async getQualityProblems() {
            let _this = this;
            try {
                let res = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/QualityProblems/GetList",
                );
                if (res.HttpCode === "200") {
                    let temp = res.Data.map(item => ({ QProblemID: item.QProblemID, QProblemName: item.QProblemName }))
                    temp.forEach(item => {
                        _this.columnsQProblem.push(item);
                    })
                }
            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },
        //调机暂停
        stopRepair() {
            Dialog.confirm({
                title: "提示",
                message: "是否确认暂停调机?",
                theme: 'round-button',
            })
                .then(() => {
                    //点击确定，继续执行后续操作
                    //填写暂停原因
                    this.resonShow = true;
                    //操作后刷新界面按钮权限
                    this.refreshBtn();
                })
                .catch(() => { });
        },

        //开始调机
        startRepair() {
            Dialog.confirm({
                title: "提示",
                message: "是否确认开始调机?",
                theme: 'round-button',
            })
                .then(() => {
                    //点击确定，继续执行后续操作
                    this.updateRepairRcord();
                    //操作后刷新界面按钮权限
                    this.refreshBtn();
                })
                .catch(() => { });
        },

        //更新调机单
        async updateRepairRcord() {
            let _this = this;
            Toast.loading({
                mask: true,
                forbidClick: true,
                duration: 0,
                message: "Loading...",
            });
            try {
                let res = await _httpClient.post(
                    _httpClient.getApiPrefix() +
                    "/app/repair/repairInfo/updateRepairStatus",
                    {
                        body: { id: _this.form.id },
                    }
                );
                if (res.code === 200) {
                    Toast.success(res.msg);
                    _this.form.status = "1"; //更新调机单为执行中
                    _this.refreshBtn();
                } else {
                    Toast.fail(res.msg);
                }
            } catch (e) {
                alert(JSON.stringify(e));
                Toast.fail(JSON.stringify(e));
            }
        },

        //故障原因下拉框确认
        faultOnConfirm(value) {
            if (value[1] == null || value[1] == "") {
                this.faultType = String(value[0]);
            } else {
                this.faultType = String(value[1]);
            }

            this.faultShowPicker = false;
        },

        //协助人选择
        openSelectUser() {
            let _this = this;
            api.openWin({
                name: "helpUser",
                url: "./maintain-toRepair-helpUser.html",
                type: "fade",
                pageParam: {
                    helpUser: _this.helpUser,
                    recordId: _this.form.id,
                },
            });
            api.addEventListener(
                {
                    name: "resultUser",
                },
                function (ret, err) {
                    if (ret.value.resultUser.length != 0) {
                        _this.helpUser = ret.value.resultUser;
                        if (_this.helpUser.length > 0) {
                            _this.helpUserStr = "";
                            _this.helpUserNameStr = "";
                            for (let i = 0; i < _this.helpUser.length; i++) {
                                switch (i) {
                                    case 0:
                                        _this.helpUserStr += _this.helpUser[i].userCode;
                                        _this.helpUserNameStr += _this.helpUser[i].userName;
                                        break;
                                    default:
                                        //默认显示三个
                                        if (i < 4) {
                                            _this.helpUserStr += "、" + _this.helpUser[i].userCode;
                                            _this.helpUserNameStr +=
                                                "、" + _this.helpUser[i].userName;
                                        }
                                }
                            }
                        }
                    }
                }
            );
        },

        //按钮权限刷新
        refreshBtn() {
            //校验当前调机单状态，初始化按钮点击权限
            switch (this.form.status) {
                case "0": //待调机
                    this.btnStartShow = false;
                    this.btnAssignShow = false;
                    this.btnStopShow = true;
                    this.btnEndShow = true;
                    break;
                case "1": //调机中
                    this.btnStartShow = true;
                    this.btnAssignShow = true;
                    this.btnStopShow = false;
                    this.btnEndShow = false;
                    break;
                case "2": //调机暂停
                    this.btnStartShow = false;
                    this.btnAssignShow = false;
                    this.btnStopShow = true;
                    this.btnEndShow = true;
                    break;
                case "3": //调机完成
                    this.btnStartShow = true;
                    this.btnAssignShow = true;
                    this.btnStopShow = true;
                    this.btnEndShow = true;
                    break;
                case "4": //调机不通过
                    this.btnStartShow = false;
                    this.btnAssignShow = false;
                    this.btnStopShow = true;
                    this.btnEndShow = true;
                    break;
                case "5": //关闭
                    this.btnStartShow = true;
                    this.btnAssignShow = true;
                    this.btnStopShow = true;
                    this.btnEndShow = true;
                    break;
                default:
                    this.btnStartShow = false;
                    this.btnAssignShow = false;
                    this.btnStopShow = false;
                    this.btnEndShow = false;
            }
        },

        //原因选择确认
        resonConfirm(value) {
            this.resonShow = false;
            this.stopResonValue = value.text;
            this.updateRepairStop();
        },
        //记录调机暂停
        async updateRepairStop() {
            let _this = this;
            Toast.loading({
                mask: true,
                forbidClick: true,
                duration: 0,
                message: "Loading...",
            });
            try {
                let res = await _httpClient.post(
                    _httpClient.getApiPrefix() +
                    "/app/repair/repairRecordTime/updateRecordTime",
                    {
                        body: {
                            recordId: _this.form.id,
                            stopReson: _this.stopResonValue,
                            type: 0,
                        },
                    }
                );
                if (res.code === 200) {
                    Toast.success(res.msg);
                    _this.form.status = "2"; //更新调机单为暂停
                    _this.refreshBtn();
                    if (_this.stopResonValue == "人员换班") {
                        //任务转派
                        _this.taskAssign();
                    }
                    _this.stopResonValue = "";
                } else {
                    Toast.fail(res.msg);
                }
            } catch (e) {
                alert(JSON.stringify(e));
                Toast.fail(JSON.stringify(e));
            }
        },
        //调机完成
        async finishRepair() {
            let _this = this;
            if (_this.faultType == "") {
                Dialog.alert({
                    message: "请选择故障类型",
                    theme: 'round-button',
                }).then(() => {
                    // on close
                });
                return;
            }
            if (
                _this.equipRepairVo.audioList.length == 0 &&
                _this.equipRepairVo.videoList.length == 0 &&
                _this.equipRepairVo.picList.length == 0
            ) {
                Toast("请先拍照或录制视频或录制语音");
                return;
            }
            _this.btnLoading = true;
            Toast.loading({
                mask: true,
                forbidClick: true,
                duration: 0,
                message: "Loading...",
            });
            try {
                let res = await _httpClient.post(
                    _httpClient.getApiPrefix() + "/app/repair/repairInfo/finishRepair",
                    {
                        body: {
                            recordId: _this.form.id,
                            stopReson: _this.stopResonValue,
                            faultType: _this.faultType,
                            sparePart: _this.sparePart,
                            finishTime: _this.getNowTime(),
                            repairUser: _this.user.nickName,
                            requestId: _this.form.requestId,
                            siteKey: _this.user.site,
                            remark: _this.equipRepairVo.remark,
                        },
                    }
                );
                //
                let res1 = await _httpClient.post(
                    _httpClient.getApiPrefix() + "/app/repair/repairInfo/saveFile",
                    {
                        body: this.equipRepairVo,
                    }
                );
                if (res.code === 200) {
                    Dialog.alert({
                        message: res.msg,
                        theme: 'round-button',
                    }).then(() => {
                        // on close
                    });
                    _this.form.status = "3"; //更新状态为调机完成
                    //调机完成，关闭当前页面
                    api.sendEvent({
                        name: "result",
                        extra: {
                            item: _this.form,
                        },
                    });
                    api.closeWin();
                } else {
                    Toast.fail(res.msg);
                }
            } catch (e) {
                alert(JSON.stringify(e));
                Toast.fail(JSON.stringify(e));
            }
        },
        //任务转派
        taskAssign() {
            let _this = this;
            Dialog.confirm({
                title: "提示",
                message: "是否确认转派任务?",
                theme: 'round-button',
            })
                .then(() => {
                    //打开人员选择界面
                    api.openWin({
                        name: "personSelect",
                        url: "./maintain-toRepair-personSelect.html",
                        type: "fade",
                    });
                    api.addEventListener(
                        {
                            name: "resultUser",
                        },
                        function (ret, err) {
                            if (ret.value.selectUser.length == 0) {
                                Dialog.alert({
                                    message: "未选择指派人员",
                                    theme: 'round-button',
                                }).then(() => {
                                    // on close
                                });
                                return;
                            }
                            let selectUser = ret.value.selectUser;
                            //更新执行人
                            _this.updateExecuter(_this.form.id, selectUser[0].userAccound);
                        }
                    );
                })
                .catch(() => { });
        },

        //更新执行人
        async updateExecuter(id, userName) {
            let _this = this;
            Toast.loading({
                mask: true,
                forbidClick: true,
                duration: 0,
                message: "Loading...",
            });
            try {
                let res = await _httpClient.post(
                    _httpClient.getApiPrefix() +
                    "/app/repair/repairInfo/updateRepairUser",
                    {
                        body: { id: id, repairUser: userName },
                    }
                );
                if (res.code === 200) {
                    Toast.clear();
                    api.sendEvent({
                        name: "result",
                        extra: {
                            item: _this.form,
                        },
                    });
                    _this.$ac.closeWin();
                } else {
                    Toast.fail(res.msg);
                }
            } catch (e) {
                Toast.clear();
                alert(JSON.stringify(e));
            }
        },

        //查询调机单协助人
        async queryHelpUser() {
            let _this = this;
            Toast.loading({
                mask: true,
                forbidClick: true,
                duration: 0,
                message: "Loading...",
            });
            try {
                let res = await _httpClient.post(
                    _httpClient.getApiPrefix() + "/app/repair/repairInfo/selectHelpUser",
                    {
                        // body: { recordId: _this.form.id },
                        body: { recordId: _this.form.id },
                    }
                );
                if (res.code === 200) {
                    Toast.clear();
                    _this.helpUser = res.rows;
                    if (_this.helpUser.length > 0) {
                        for (let i = 0; i < _this.helpUser.length; i++) {
                            switch (i) {
                                case 0:
                                    _this.helpUserStr += _this.helpUser[i].userCode;
                                    _this.helpUserNameStr += _this.helpUser[i].userName;
                                    break;
                                default:
                                    //默认显示三个
                                    if (i < 4) {
                                        _this.helpUserStr += "、" + _this.helpUser[i].userCode;
                                        _this.helpUserNameStr += "、" + _this.helpUser[i].userName;
                                    }
                            }
                        }
                    }
                } else {
                    Toast.fail(res.msg);
                }
            } catch (e) {
                Toast.clear();
                alert(JSON.stringify(e));
            }
        },

        //初始化查询故障信息
        async queryEmFault() {
            let _this = this;
            Toast.loading({
                mask: true,
                forbidClick: true,
                duration: 0,
                message: "Loading...",
            });
            try {
                let res = await _httpClient.post(
                    _httpClient.getApiPrefix() + "/app/repair/repairInfo/selectEmFault",
                    {
                        body: { siteKey: _this.user.site },
                    }
                );
                if (res.code === 200) {
                    Toast.clear();
                    _this.faultTypes = res.rows;
                } else {
                    Toast.fail(res.msg);
                }
            } catch (e) {
                Toast.clear();
                alert(JSON.stringify(e));
            }
        },

        //初始化查询调机暂停原因
        async queryEmStopReson() {
            let _this = this;
            Toast.loading({
                mask: true,
                forbidClick: true,
                duration: 0,
                message: "Loading...",
            });
            try {
                let res = await _httpClient.get(
                    _httpClient.getApiPrefix() +
                    "/system/dict/data/type/sys_repair_stop_reson"
                );
                if (res.code === 200) {
                    Toast.clear();
                    if (res.data.length > 0) {
                        for (let i = 0; i < res.data.length; i++) {
                            let reson = { text: res.data[i].dictValue };
                            _this.stopReson.push(reson);
                        }
                    } else {
                        _this.stopReson = [];
                    }
                } else {
                    Toast.fail(res.msg);
                }
            } catch (e) {
                Toast.clear();
                alert(JSON.stringify(e));
            }
        },


    },
};
</script>
<style>
body {
    background-color: White;
}

.pic {
    width: 100%;
    text-align: center;
}

.clickbtn {
    width: 1;
    margin: 5px 10px;
    line-height: 45px;
    border: 1px #ccc dashed;
    text-align: center;
}

.buttonColor {
    background-color: #ff9933;
    border-color: #ff9933;
}

.buttonColor2 {
    background-color: #1076c0;
    border-color: #1076c0;
}

.message {
    font-size: 15px;
    margin-top: 5px;
    margin-left: -10px;
    font-weight: bold;
}

.divStyle {
    border: 1px solid #dcdcdc;
    border-top-width: 3px;
    border-left-width: 3px;
    margin-left: 5px;
    margin-right: 4px;
    margin-top: 4px;
}

.pagination {
    position: fixed;
    bottom: 15px;
    width: 300px;
    margin-left: 10%;
    color: rgb(0, 0, 255);
    text-align: center;
}

.divMedia {
    margin-top: 0px;
    height: 230px;
    border: solid #dcdcdc;
    margin-left: 5px;
    margin-right: 15px;
    border-top-width: 4px;
    border-left-width: 4px;
    border-right-width: 1px;
    border-bottom-width: 1px;
}

.divMedia2 {
    margin-top: 0px;
    height: 160px;
    border: solid #dcdcdc;
    margin-left: 5px;
    margin-right: 15px;
    border-top-width: 4px;
    border-left-width: 4px;
    border-right-width: 1px;
    border-bottom-width: 1px;
}

.button {
    position: fixed;
    left: 5px;
    right: 5px;
    bottom: 24px;
    width: 100%;
    height: 30px;
    font-size: 12px;
}

.divMessage {
    margin-top: 0px;
    border: solid #dcdcdc;
    margin-left: 5px;
    margin-right: 15px;
    border-top-width: 4px;
    border-left-width: 4px;
    border-right-width: 1px;
    border-bottom-width: 1px;
}

.Field {
    font-weight: bold;
    font-size: 15px;
    color: #9c8e8e;
    height: 45px;
}

.Field2 {
    font-weight: bold;
    font-size: 15px;
    color: #9c8e8e;
}

.textScroll {
    display: inline-block;
    position: fixed;
    top: 5rem;
    bottom: 0rem;
    overflow: scroll;
    right: 0;
    width: 100%;
    z-index: 1;
}
</style>
  